package com.acyouzi.leetcode.array;

/**
 * 17/9/11 15:32
 *
 * @author sunxu
 */
public class ThirdMaximum {
  public static int thirdMax(int[] nums) {
    int max1 = Integer.MIN_VALUE;
    int max2 = Integer.MIN_VALUE;
    int max3 = Integer.MIN_VALUE;
    for (int i : nums){
      if (max1 < i){
        max3 = max2;
        max2 = max1;
        max1 = i;
      }else if (max2 < i){
        max3 = max2;
        max2 = i;
      }else if (max3 < i){
        max3 = i;
      }
    }
    return max3 != Integer.MIN_VALUE ? max3 : max2 != Integer.MIN_VALUE ? max2:max1;
  }

  public static void main(String[] args) {
    System.out.println(thirdMax(new int[]{1,2}));
  }
}
